		TITLE	INSTGRP - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	GROUPS

		PUBLIC	INSTALL_GROUP,GET_GROUP,INSTALL_GROUP_SYMBOL


		.DATA

		EXTERNDEF	SYMBOL_TEXT:BYTE

		EXTERNDEF	SYMBOL_HASH:DWORD,SYMBOL_LENGTH:DWORD,GROUP_HASH:DWORD,LAST_GROUP_GINDEX:DWORD
		EXTERNDEF	FIRST_GROUP_GINDEX:DWORD,GROUP_NAME_LINDEX:DWORD,DGROUP_GINDEX:DWORD,FLAT_GINDEX:DWORD
		EXTERNDEF	GROUP_HASH_TABLE_PTR:DWORD,GROUP_PTRS:DWORD,GROUP_PTRS_PTR:DWORD,GROUP_COUNT:DWORD
		EXTERNDEF	FIRST_CV_GROUP_GINDEX:DWORD,LAST_CV_GROUP_GINDEX:DWORD

		EXTERNDEF	LNAME_LARRAY:LARRAY_STRUCT,GROUP_GARRAY:STD_PTR_S,DGROUP_TPTR:TPTR_STRUCT,SYMBOL_TPTR:TPTR_STRUCT

		EXTERNDEF	CASE_STRING_COMPARE:DWORD


		.CODE	PASS1_TEXT


INSTALL_GROUP	PROC
		;
		;RETURNS EAX=GINDEX, ECX IS PHYS
		;
		MOV	EAX,GROUP_NAME_LINDEX
		PUSH	ESI

		CONVERT_LINDEX_EAX_EAX	LNAME_LARRAY,ESI

		PUSHM	EDI,EBX
		ASSUME	EAX:PTR TPTR_STRUCT

		MOV	EDI,OFF SYMBOL_TPTR
		ASSUME	EDI:PTR TPTR_STRUCT
		MOV	EBX,[EAX]._TP_FLAGS

		MOV	EDX,[EAX]._TP_HASH
		MOV	ECX,[EAX]._TP_LENGTH

		ADD	EDX,EBX
		MOV	[EDI]._TP_LENGTH,ECX

		SHR	ECX,2
		LEA	ESI,[EAX]._TP_TEXT

		MOV	[EDI]._TP_HASH,EDX
		INC	ECX

		LEA	EDI,[EDI]._TP_TEXT
		POP	EBX

		OPTI_MOVSD

		POPM	EDI,ESI

INSTALL_GROUP_SYMBOL	LABEL	PROC
		;
		;SYMBOL_TEXT CLASS NAME, EDX IS HASH, RETURNS EAX=GINDEX, ECX IS PTR
		;
		ASSUME	EAX:NOTHING

		PUSH	EBX
		MOV	EAX,EDX

		XOR	EDX,EDX
		MOV	ECX,EAX

		MOV	EBX,GROUP_HASH_TABLE_PTR

		HASHDIV	GROUP_HASH

		PUSHM	EDI,ESI

		MOV	EAX,DPTR [EBX+EDX*4]
		LEA	EBX,[EBX+EDX*4 - GROUP_STRUCT._G_NEXT_HASH_GINDEX]
GROUP_NEXT:
		TEST	EAX,EAX
		JZ	DO_GROUP_INSTALL

		MOV	EDX,EAX
		CONVERT	EAX,EAX,GROUP_GARRAY
		ASSUME	EAX:PTR GROUP_STRUCT
		MOV	EBX,EAX
		ASSUME	EBX:PTR GROUP_STRUCT

		MOV	EDI,[EAX]._G_HASH
		MOV	EAX,[EAX]._G_NEXT_HASH_GINDEX

		CMP	ECX,EDI
		JNZ	GROUP_NEXT
		;
		;OK, TEST TEXT FOR MATCH
		;
		PUSHM	ECX
		MOV	EDI,OFF SYMBOL_TEXT

		MOV	ECX,SYMBOL_LENGTH
		LEA	ESI,[EBX]._G_TEXT

		CALL	CASE_STRING_COMPARE

		POPM	ECX
		JNZ	GROUP_NEXT

		POPM	ESI,EDI

		MOV	ECX,EBX
		POP	EBX

		MOV	EAX,EDX
		SUB	EDX,-1			;CARRY MEANS INSTALL FAILED, ALREADY THERE

		RET

DO_GROUP_INSTALL:
		POPM	ESI,EDI

		MOV	EDX,ECX
		MOV	ECX,EBX

		POP	EBX

INSTALL_GROUP	ENDP

GET_GROUP	EQU	INSTALL_GROUP


ALLOC_GROUP	PROC
		;
		;EDX IS HASH, [ECX] GETS POINTER
		;
		PUSHM	EDI,ESI,EBX
		MOV	EAX,SYMBOL_LENGTH

		PUSH	EDX
		ADD	EAX,SIZE GROUP_STRUCT-3

		MOV	ESI,ECX
		ASSUME	ESI:PTR GROUP_STRUCT
		GROUP_POOL_ALLOC		;ES:DI IS PHYS, AX LOG

		MOV	EBX,EAX
		ASSUME	EBX:PTR GROUP_STRUCT

		INSTALL_POINTER_GINDEX	GROUP_GARRAY
		MOV	EDX,EAX

		MOV	[ESI]._G_NEXT_HASH_GINDEX,EAX
		XOR	EAX,EAX

		MOV	ECX,GROUP_STRUCT._G_TEXT/4
		MOV	EDI,EBX

		REP	STOSD

		MOV	ESI,OFF SYMBOL_TEXT
		ASSUME	ESI:NOTHING
		DEC	ECX

		POP	EAX
		MOV	[EBX]._G_OFFSET,ECX	;SET OFFSET TO -1 FOR DETERMINING LOWEST FOR OVERLAYS

		MOV	ECX,[ESI-4]
		MOV	[EBX]._G_HASH,EAX

		SHR	ECX,2
		PUSH	EDX

		INC	ECX
		MOV	EDX,DGROUP_TPTR._TP_HASH

		REP	MOVSD

		CMP	EDX,EAX
		JNZ	L1$
		;
		;HASH MATCHES DGROUP, WHAT ELSE?
		;
		MOV	ESI,OFF DGROUP_TPTR._TP_TEXT
		LEA	EDI,[EBX]._G_TEXT

		MOV	ECX,DGROUP_TPTR._TP_LENGTH
		POP	EDX

		CALL	CASE_STRING_COMPARE

		MOV	AL,[EBX]._G_TYPE1
		JNZ	L11$

		OR	AL,MASK GROUP_IS_DGROUP
		MOV	DGROUP_GINDEX,EDX

		MOV	[EBX]._G_TYPE1,AL
		JMP	L2$

L1$:
		POP	EDX
L11$:
		MOV	EAX,SYMBOL_LENGTH

		CMP	EAX,4
		JNZ	L2$

		MOV	ECX,DPTR SYMBOL_TEXT
		MOV	AL,[EBX]._G_TYPE1

		CMP	ECX,'TALF'
		JNZ	L2$

		OR	AL,MASK GROUP_IS_FLAT
		MOV	FLAT_GINDEX,EDX

		MOV	[EBX]._G_TYPE1,AL
L2$:
		MOV	ECX,GROUP_COUNT
		MOV	EAX,LAST_GROUP_GINDEX

		MOV	[EBX]._G_NUMBER,ECX

		INC	ECX
		TEST	EAX,EAX

		MOV	GROUP_COUNT,ECX
		JZ	GROUP_FIRST

		CONVERT	EAX,EAX,GROUP_GARRAY
		ASSUME	EAX:PTR GROUP_STRUCT

		MOV	[EAX]._G_NEXT_GROUP_GINDEX,EDX
		MOV	LAST_GROUP_GINDEX,EDX

if	fg_cv
		MOV	EAX,LAST_CV_GROUP_GINDEX
		MOV	LAST_CV_GROUP_GINDEX,EDX

		CONVERT	EAX,EAX,GROUP_GARRAY
		ASSUME	EAX:PTR GROUP_STRUCT

		MOV	[EAX]._G_NEXT_CV_GINDEX,EDX
endif

		CMP	ECX,16
		MOV	ECX,GROUP_PTRS_PTR

		MOV	EAX,EDX
		JA	L5$

		MOV	[ECX],EDX
		ADD	ECX,4

		MOV	GROUP_PTRS_PTR,ECX

L5$:

		;RETURN EAX IS GROUP, ECX IS PHYS

		MOV	ECX,EBX
		POP	EBX

		POPM	ESI,EDI
		RET

GROUP_FIRST:
		MOV	GROUP_PTRS,EDX
		MOV	ECX,EBX

		MOV	GROUP_PTRS_PTR,OFF GROUP_PTRS+4

		POPM	EBX,ESI,EDI
		MOV	EAX,EDX
		MOV	FIRST_GROUP_GINDEX,EDX
		MOV	LAST_GROUP_GINDEX,EAX
if	fg_cv
		MOV	FIRST_CV_GROUP_GINDEX,EAX
		MOV	LAST_CV_GROUP_GINDEX,EAX
endif
		RET

ALLOC_GROUP	ENDP


		END

